'use strict';
// Copyright 2014 Blueant Inc. All Rights Reserved.

/**
 * @fileoverview 战斗
 * @author sundbcn@gmail.com (sun debing)
 */

var moment = require('moment');
var modelUtil = require('../util/modelUtil');
var mongoConnector = require('../libs/mongodb/mongoConnector');
/* jshint unused:false */
var rebelSchema = require('../schemas/rebelSchema');
var Rebel = mongoConnector().model('Rebel');

/**
 * 根据角色id获取掠夺数据
 */
module.exports.getByRoleId = function (role_id, cb) {
    modelUtil.getByRoleId(Rebel, role_id, function (err, rebel_model) {
        if (!!err) {
            return cb(err);
        }
        _refreshTodayPassRebel(rebel_model);
        cb(null, rebel_model);
    });
};

/**
 * 刷新当天通过的
 * @param  {[type]} rebel_model [description]
 * @return {[type]}             [description]
 */
var _refreshTodayPassRebel = function (rebel_model) {
    if (moment(rebel_model.getLastRefreshTime()) <= moment().startOf('day')) {
        rebel_model.refreshTodayPassRebel();
    }
};
